import {Component, OnInit} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';

@Component({
  selector: 'app-http',
  templateUrl: './http.component.html',
  styleUrls: ['./http.component.scss']
})
export class HttpComponent implements OnInit {
  public myList: Array<any> = [];

  constructor(public httpClient: HttpClient) {
  }

  ngOnInit(): void {
  }

  getRequest() {
    let token: string = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIzIiwiaWF0IjoxNTg3MzU1MjY4LCJleHAiOjE1ODc5NjAwNjh9._VZAT7paHDO8hPnfynF2_TeJ3mMeuH9a1iqo7J2DOcnkoBw2wioGJcXnAFutwZZudjqzjxrBHJh9TKyEZuxAuw';
    let api = 'http://192.168.31.32:8080/renren-fast/app/video/list?token=' + token;
    this.httpClient.get(api).subscribe((res) => {
      // @ts-ignore
      console.log(res.page.list);
      // @ts-ignore
      this.myList = res.page.list;
    });
  }

  postRequest() {
    const httpOptions = {
      headers: new HttpHeaders({'Content-Type': 'application/json'})
    };

    let api = 'http://localhost:8080/renren-fast/app/login';
    this.httpClient.post(api, {
      'mobile': 'demoData',
      'password': 'demoData'
    }, httpOptions).subscribe((res) => {
      console.log(res);
    });
  }
}
